package com.powernode.config;

import com.alibaba.fastjson.JSONObject;
import com.powernode.common.LxlEmail;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Date 2022/4/8 22:14
 * @Version 1.0
 */
@Component
@Aspect
public class LlxAop {

    @Resource
    RabbitTemplate rabbitTemplate;

//    @Resource
//    JavaMailSender javaMailSender;

    @AfterReturning(value = "execution(public * com.powernode.service.impl.UmsUserServiceImpl.add(..))")
    public void afterUserAdd(JoinPoint joinPoint) {
//        //取出参数列表
        Object[] args = joinPoint.getArgs();
        String name = args[0].toString();
        String phone = args[1].toString();
        String email = args[2].toString();
        String password = args[3].toString();

        LxlEmail lxlEmail = new LxlEmail(
                email,
                "测试消息",
                "系统为您创建了用户,登录名："+ phone + "密码：" + password
        );

        rabbitTemplate.convertAndSend("email", JSONObject.toJSONString(lxlEmail));
//
//        SimpleMailMessage mailMessage = new SimpleMailMessage();
//        mailMessage.setSubject("测试消息");
//        mailMessage.setTo(email);
//        mailMessage.setFrom("1102549801@qq.com");
//        mailMessage.setText("系统为您创建了用户,登录名："+ phone + "密码：" + password);

//        javaMailSender.send(mailMessage);
    }
}
